package pl.nith.battleships.windows.panels;

import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import pl.nith.battleships.managers.Manager;
import pl.nith.battleships.resources.i18n.GameLocale;

public class MainWindowMenuBar extends JMenuBar
{
	private static final long	serialVersionUID		= 7318778663497789794L;

	private JMenu				fileMenu				= null;
	private JMenu				optionsMenu				= null;
	private JMenu				helpMenu				= null;

	private JMenuItem			fileMenu_StartServer	= null;
	private JMenuItem			fileMenu_Connect		= null;
	private JMenuItem			fileMenu_Exit			= null;
	private JMenuItem			optionsMenu_Config		= null;
	private JMenuItem			helpMenu_About			= null;

	public MainWindowMenuBar()
	{
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

		setPreferredSize(new Dimension(260, 20));
		setName("MenuBar");

		add(getFileMenu());
		add(getOptionsMenu());
		add(getHelp_Menu());
		
		setVisible(true);
	}

	/**
	 * This method initializes fileMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getFileMenu()
	{
		if (fileMenu == null)
		{
			fileMenu = new JMenu();

			fileMenu.setText(GameLocale.getMenuBar().getString("file"));
			fileMenu.add(getFileMenu_StartServer());
			fileMenu.add(getFileMenu_Connect());
			fileMenu.add(getFileMenu_Exit());
		}

		return fileMenu;
	}

	private JMenu getOptionsMenu()
	{
		if (optionsMenu == null)
		{
			optionsMenu = new JMenu();

			optionsMenu.setText(GameLocale.getMenuBar().getString("options"));
			optionsMenu.add(getOptionsMenu_Config());
		}

		return optionsMenu;
	}

	/**
	 * This method initializes helpMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getHelp_Menu()
	{
		if (helpMenu == null)
		{
			helpMenu = new JMenu();

			helpMenu.setText(GameLocale.getMenuBar().getString("help"));
			helpMenu.add(getHelpMenu_About());
		}

		return helpMenu;
	}

	/**
	 * This method initializes fileMenu_StartServer
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getFileMenu_StartServer()
	{
		if (fileMenu_StartServer == null)
		{
			fileMenu_StartServer = new JMenuItem();

			fileMenu_StartServer.setText(GameLocale.getMenuBar().getString("file_startserver"));
			fileMenu_StartServer.setActionCommand("START_SERVER");
			
			fileMenu_StartServer.addActionListener(Manager.getActionListener());
		}

		return fileMenu_StartServer;
	}

	/**
	 * This method initializes fileMenu_Connect
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getFileMenu_Connect()
	{
		if (fileMenu_Connect == null)
		{
			fileMenu_Connect = new JMenuItem();

			fileMenu_Connect.setText(GameLocale.getMenuBar().getString("file_connect"));
			fileMenu_Connect.setActionCommand("CONNECT");
			
			fileMenu_Connect.addActionListener(Manager.getActionListener());
		}

		return fileMenu_Connect;
	}

	/**
	 * This method initializes fileMenu_Exit
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getFileMenu_Exit()
	{
		if (fileMenu_Exit == null)
		{
			fileMenu_Exit = new JMenuItem();

			fileMenu_Exit.setText(GameLocale.getMenuBar().getString("file_exit"));
			fileMenu_Exit.setActionCommand("EXIT");
			
			fileMenu_Exit.addActionListener(Manager.getActionListener());
		}

		return fileMenu_Exit;
	}

	/**
	 * This method initializes optionspMenu_Config
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getOptionsMenu_Config()
	{
		if (optionsMenu_Config == null)
		{
			optionsMenu_Config = new JMenuItem();
			optionsMenu_Config.setText(GameLocale.getMenuBar().getString(
							"options_config"));
			optionsMenu_Config.setActionCommand("CONFIG");
			
			optionsMenu_Config.addActionListener(Manager.getActionListener());
		}

		return optionsMenu_Config;
	}

	/**
	 * This method initializes helpMenu_About
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getHelpMenu_About()
	{
		if (helpMenu_About == null)
		{
			helpMenu_About = new JMenuItem();
			helpMenu_About.setText(GameLocale.getMenuBar().getString(
							"help_about"));
			helpMenu_About.setActionCommand("ABOUT");
			
			helpMenu_About.addActionListener(Manager.getActionListener());
		}

		return helpMenu_About;
	}
}
